<template>
    <div class="personal-info">
        <el-form label-position="right" label-width="100px">
            <el-form-item label="昵称:" style="width:70%">
                <el-input v-model="userInfo.nickName"></el-input>
            </el-form-item>
            <el-form-item label="账号:">
                {{userInfo.account}}
            </el-form-item>
            <el-form-item label="我的签名:" style="width:90%">
                <el-input
                    type="textarea"
                    :rows="3"
                    placeholder="设置您的签名- ( ゜- ゜)つロ"
                    v-model="userInfo.sign"
                    >
                </el-input>
            </el-form-item>

            <el-form-item label="性别:">
                <div class="chaos-button-div">
                    <div v-bind:class="{'button-male-click': isButtonMaleClick }" @click="buttonMaleClick" class="button-male">
                        <i class="el-icon-male"></i>
                        <span>男</span>
                    </div>
                    <div v-bind:class="{'button-female-click': isButtonFemaleClick }" @click="buttonFemaleClick" class="button-female">
                        <i class="el-icon-female"></i>
                        <span>女</span>
                    </div>
                </div>

            </el-form-item>

            <el-form-item label="出生日期:">
                <el-date-picker
                    type="date"
                    placeholder="选择出生日期"
                    format="yyyy-MM-dd"
                    v-model="userInfo.birthday"
                    :picker-options="birthdayPickerOptions">
                </el-date-picker>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="doUpdateUserInfo">保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "personalInfo",
        data(){
            return{
                birthdayPickerOptions:{
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    }
                },
                isButtonMaleClick:false,
                isButtonFemaleClick:false,
                userInfo:{
                    account:'',
                    nickName:'',
                    sign:'',
                    sex:'',
                    birthday:''
                }
            }
        },
        created(){
            var self = this;
            self.$api.get('userController/getUserInfo',null, result => {
                self.userInfo = result;
                if(result.sex==='0'){
                    self.buttonMaleClick();
                }

                if(result.sex==='1'){
                    self.buttonFemaleClick();
                }


            });
        },
        methods:{
            doUpdateUserInfo(){
                var self = this;
                self.$api.post('userController/updateUserInfo',self.userInfo, result => {
                    if(result==='SAVE_USERINFO_SUCCESS'){
                        self.$notify({
                            title: '更新成功',
                            message: '用户信息更新成功',
                            type: 'success',
                            position: 'bottom-right'
                        });
                    }
                });
            },
            buttonMaleClick(){
                this.isButtonMaleClick = true;
                this.isButtonFemaleClick = false;
                this.userInfo.sex = 0;
            },
            buttonFemaleClick(){
                this.isButtonFemaleClick = true;
                this.isButtonMaleClick = false;
                this.userInfo.sex = 1;
            }
        }
    }
</script>

<style type="text/css">
    .personal-info{
        width:70%;
        min-height:400px;
        margin-left:10%;
        margin-top:40px;
        color:#898989;
    }

    .chaos-button-div .el-button--primary.is-plain {
            color: #409EFF;
            background: #ffffff;
            border-color: #409EFF;
    }

    .button-male{
        color: #409EFF;
        background-color: #ffffff;
        border:1px solid #409EFF;
        border-radius:3px;
        width:60px;
        height:32px;
        line-height:32px;
        text-align:center;
        cursor:pointer;
        float:left;
    }

    .button-male-click{
        background-color:#409EFF;
        color:#ffffff;
    }

    .button-female{
        color: #FB7299;
        background-color: #ffffff;
        border:1px solid #FB7299;
        border-radius:3px;
        width:60px;
        height:32px;
        line-height:32px;
        text-align:center;
        cursor:pointer;
        margin-left:10px;
        float:left;
    }

    .button-female-click{
        background-color:#FB7299;
        color:#ffffff;
    }



</style>
